//
//  HSReplayView.swift
//  HomeSchoolDemo
//
//  Created by rimi on 16/10/11.
//  Copyright © 2016年 黄华强. All rights reserved.
//

import UIKit

class HSReplayView: UIView {

    @IBOutlet weak var likeNameL: UILabel!
    
    @IBOutlet weak var likeLineView: UIView!
//创建一个保存回复数据标签的数组
    var replayArray: [UILabel] = []
    
    
    var messageVM: HSMessagesViewModel? {
        didSet {
            
            setupUI()
        }
    }
    
    fileprivate func setupUI() {
        //添加之前移除
        for l in replayArray {
            l.removeFromSuperview()
        }
        replayArray.removeAll()
        
        //获得点赞人数
        let linkeN = messageVM?.message.likenum ?? 0
        
        likeNameL.attributedText = messageVM?.likeNameAttribute
        likeNameL.numberOfLines = 0
        
        let replayNum = messageVM?.message.replaylist?.count ?? 0
        
        //处理分割线显示
        if linkeN > 0 && replayNum > 0 {
            likeLineView.isHidden = false
        } else {
            likeLineView.isHidden = true
        }
        
        //获得回复列表数据
        guard let arr = messageVM?.replayAttributeArray else {
            return
        }
        
        for attStr in arr {
            //初始化
            let l = UILabel(attributeTitle: attStr, fontSize: 13)
            l.numberOfLines = 0
            replayArray.append(l)
            addSubview(l)
        }
        
        
        
        for (i,l) in replayArray.enumerated() {
            l.snp.makeConstraints({ (mark) in
                mark.left.equalTo(8)
                mark.right.equalTo(-8)
                if i == 0 {
                    if linkeN == 0 {
                        mark.top.equalTo(12)
                    } else {
                        mark.top.equalTo(likeLineView.snp.bottom).offset(5)
                    }
                    
                } else {
                    
                    mark.top.equalTo(replayArray[i-1].snp.bottom).offset(5)
                    
                }
            })
            
        }
        
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
    }
    
}
